<?php

namespace App\Task;

use App\Model\User;
use App\Model\VideoCall;
use Hyperf\Crontab\Annotation\Crontab;

/**
 * 定时检测当前视频通话（时长和费用）
 * @Crontab(name="CheckVideoTask", rule="*\/9 * * * * *", callback="execute", memo="检测当前通话状态",singleton=false)
 */
class CheckVideoTask extends CheckTaskBase
{
    /**
     * @return void
     */
    public function execute()
    {
        //获取当前正在通话的记录（排除新手福利语聊记录）
        $callingLogs = VideoCall::getChatting();
        $count = count($callingLogs);
        log_info(__CLASS__ . "==docheck==Count:{$count}");
        if (!$count) return;
        //语音
        array_walk($callingLogs, function ($callingLog) {
            //与小助手的对话
            if (User::checkOfficial([$callingLog['user_id'], $callingLog['chat_user_id']])) {
                log_info(__CLASS__ . "==official==LogId:{$callingLog['id']}");
                return;
            }
            $this->runCheck($callingLog);
        });
    }
}
